﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using RFVisualisation.Common;
using RFVisualisation.DataVis.GraphTypes;
using RFVisualisation.DataVis;

namespace TestApp {
	public partial class Form1 : Form {
		TabPage[] tabs;
		Graph[] graphs={
							 new XYGraph(),
							 new SmithChart()
						 };

		public Form1() {
			InitializeComponent();

			BasicRecordset rs = new BasicRecordset();
			rs.addChannel( "X", typeof( double ) );
			rs.addChannel( "Y", typeof( double ) );
			rs.addRecord( 0.1, 0.2 );
			rs.addRecord( 0.3, 0.4 );
			rs.addRecord( 0.5, 0.6 );
			rs.addRecord( 0.7, 0.8 );
			tabs = new TabPage[graphs.Length];
			for (int i = 0; i < graphs.Length; i++) {
				tabs[i] = new TabPage();
				tabs[i].Text = graphs[i].GetType().Name;
				tabs[i].Controls.Add( graphs[i] );
				graphs[i].PlotAreaR = new RectangleF( 0.1f, 0.1f, 0.8f, 0.8f );
				graphs[i].Recordset = rs;
				tabControl1.Controls.Add( tabs[i] );
			}
			sizeAll();
		}

		public static void Main( String[] args ) {
			Application.Run( new Form1() );
		}

		private void Form1_FormClosing( object sender, FormClosingEventArgs e ) {
			//Important: Must kill all threads for program to exit
			RFVisualisation.DataVis.GraphicsThreadController.KillAll();
		}

		private void sizeAll() {
			tabControl1.SetBounds( 10, 10, Width - 40, Height - 60 );
			for (int i = 0; i < graphs.Length; i++) {
				graphs[i].SetBounds( 10, 10, tabControl1.Width - 20, tabControl1.Height - 20 );
			}
		}

		private void Form1_Resize( object sender, EventArgs e ) {
			sizeAll();
		}

	}
}
